//
//  PersonalInfoViewController.m
//  HotWord
//
//  Created by Rainbow on 7/24/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "PersonalInfoViewController.h"
#import "UserHeadInfoCell.h"
#import "UserInfoCell.h"
#import "InboxViewController.h"
#import "PeopleNearViewController.h"
#import "ServiceHelper.h"
#import "MessageManager.h"
#import "ITTImageCacheManager.h"


@interface PersonalInfoViewController ()

- (void)hideKeybord;

@end

@implementation PersonalInfoViewController
@synthesize personalInfoTableView;
@synthesize backBtn;
@synthesize inboxBtn;
@synthesize friendBtn;
@synthesize meHeaderView;
@synthesize logoutFooterView;
@synthesize dataSelectPicker;
@synthesize pickContainerView;
@synthesize editBtn;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.backBtn.alpha = 0;
    self.inboxBtn.alpha = 0;
    self.friendBtn.alpha = 0;
    self.personalInfoTableView.top = self.view.height;
    self.personalInfoTableView.tableHeaderView = self.meHeaderView;
    self.personalInfoTableView.tableFooterView = self.logoutFooterView;
    UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hanldTapGesture:)];
    tapGestureRecognizer.delegate = self;
    [self.view addGestureRecognizer:tapGestureRecognizer];

    _tempUser = [[User alloc] init];
    [_tempUser copyFromUser:[UserManager sharedManager].currentUser];
    [self receiveMessageNotification];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveMessageNotification) name:NOTIFICATION_RECEIVE_MESSAGE object:nil];
}

- (void)receiveMessageNotification
{
    if ([MessageManager sharedManager].newMessageCount > 0) {
        [self.inboxBtn setImage:nil forState:UIControlStateNormal];
        [self.inboxBtn setImage:nil forState:UIControlStateHighlighted];
        [self.inboxBtn setBackgroundImage:[UIImage imageNamed:@"inbox_indicator.png"] forState:UIControlStateNormal];
        [self.inboxBtn setBackgroundImage:[UIImage imageNamed:@"inbox_indicator.png"] forState:UIControlStateHighlighted];
        [self.inboxBtn setTitle:[NSString stringWithFormat:@"%d",[MessageManager sharedManager].newMessageCount] forState:UIControlStateNormal];
    }
    else {
        
        [self.inboxBtn setImage:[UIImage imageNamed:@"inbox_btn.png"] forState:UIControlStateNormal]; 
        [self.inboxBtn setImage:[UIImage imageNamed:@"inbox_btn.png"] forState:UIControlStateHighlighted];        
        [self.inboxBtn setBackgroundImage:nil forState:UIControlStateNormal];
        [self.inboxBtn setBackgroundImage:[UIImage imageNamed:@"tap_light.png"] forState:UIControlStateHighlighted];
        [self.inboxBtn setTitle:nil forState:UIControlStateNormal];
    }
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    if (!_isEditing) {
        [_tempUser copyFromUser:[UserManager sharedManager].currentUser];
    }
    self.pickContainerView.top = self.view.height;
    [self receiveMessageNotification];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [UIView animateWithDuration:0.5 
                     animations:^{
                         self.backBtn.alpha = 1;
                         self.inboxBtn.alpha = 1;
                         self.friendBtn.alpha = 1;
                         self.personalInfoTableView.top = 0;
                     }];
}

- (void)viewWillDisappear:(BOOL)animated
{  
//    if (_isEditing) {
//        _isEditing = NO;
//        
//        [self.editBtn setBackgroundImage:[UIImage imageNamed:@"edit_light.png"] forState:UIControlStateHighlighted];
//        [self.editBtn setImage:[UIImage imageNamed:@"edit_btn.png"] forState:UIControlStateNormal];
//        [self.editBtn setImage:[UIImage imageNamed:@"edit_btn.png"] forState:UIControlStateHighlighted];
//        [self.editBtn addTarget:self action:@selector(tapOnUpdateBtn:) forControlEvents:UIControlEventTouchUpInside];
//        [self.personalInfoTableView reloadData];
//    }
    [[HTActivityIndicator currentIndicator] hide];
    [super viewWillDisappear:animated];
    [UIView animateWithDuration:0.3 
                     animations:^{
                         self.backBtn.alpha = 0;
                         self.inboxBtn.alpha = 0;
                         self.friendBtn.alpha = 0;
                     }];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row == 0) {
        static NSString *CellIdentifier = @"UserHeadInfoCell";
        
        UserHeadInfoCell *cell = (UserHeadInfoCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if (cell == nil) {
            cell = [[[NSBundle mainBundle] loadNibNamed:@"UserHeadInfoCell" owner:self options:nil] objectAtIndex:0];
            cell.delegate = self;
        }
        [cell setUser:_tempUser];
        return cell;
    }
    else {
        static NSString *CellIdentifier = @"UserInfoCell";
        
        UserInfoCell *cell = (UserInfoCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if (cell == nil) {
            cell = [[[NSBundle mainBundle] loadNibNamed:@"UserInfoCell" owner:self options:nil] objectAtIndex:0];
            cell.delegate = self;
        }
        
        if (indexPath.row == 1) {
            [cell setInfoTitle:@"Gender" infoValue:_tempUser.gender pickMode:YES];
        }else if (indexPath.row == 2){
            [cell setInfoTitle:@"Test" infoValue:_tempUser.exam pickMode:YES];
        }else if (indexPath.row == 3){
            [cell setInfoTitle:@"Age" infoValue:_tempUser.year pickMode:YES];
        }else if (indexPath.row == 4){
            [cell setInfoTitle:@"Country/City" infoValue:_tempUser.country pickMode:NO];
        }else if (indexPath.row == 5){
            [cell setInfoTitle:@"School/Major" infoValue:_tempUser.city pickMode:NO];
        }else if (indexPath.row == 6){
            [cell setInfoTitle:@"I Am Looking For..." infoValue:_tempUser.dreamSchoolCN pickMode:YES];
        }else if (indexPath.row == 7){
            [cell setInfoTitle:@"What's up" infoValue:_tempUser.status pickMode:NO];
        }
        cell.indexPath = indexPath;
        [cell setIsEditing:_isEditing];
        return cell;
    }
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.row == 0) {
        return 80;
    }
    else if (indexPath.row == 7) {
        return 120;
    }
    return 50;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 8;
}

- (void)viewDidUnload
{
    [self setPersonalInfoTableView:nil];
    [self setBackBtn:nil];
    [self setInboxBtn:nil];
    [self setFriendBtn:nil];
    [self setMeHeaderView:nil];
    [self setLogoutFooterView:nil];
    [self setDataSelectPicker:nil];
    [self setPickContainerView:nil];
    [self setEditBtn:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (IBAction)tapOnBackBtn:(id)sender {
    [self.navigationController popToRootViewControllerAnimated:YES];
}

- (IBAction)tapOnInboxBtn:(id)sender {
    InboxViewController * inboxViewController = [[[InboxViewController alloc] init] autorelease];
    [self.navigationController pushViewController:inboxViewController animated:NO];
}

- (IBAction)tapOnFriendBtn:(id)sender {
    
    PeopleNearViewController * peopleNearViewController = [[[PeopleNearViewController alloc] init] autorelease];
    [self.navigationController pushViewController:peopleNearViewController animated:YES];
}

- (IBAction)tapOnLogoutBtn:(id)sender {
    [[ITTImageCacheManager sharedManager] clearDiskCache];
    [[ITTImageCacheManager sharedManager] clearMemoryCache];
    
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:@"Are you sure logout?" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Logout", nil];
    [alertView show];
    [alertView release];
}

- (IBAction)tapOnUpdateBtn:(id)sender {
    
    _isEditing = YES;
    [self.personalInfoTableView reloadData];
    [self.editBtn setBackgroundImage:[UIImage imageNamed:@"editok_light.png"] forState:UIControlStateHighlighted];
    [self.editBtn setImage:[UIImage imageNamed:@"editok_btn.png"] forState:UIControlStateNormal];
    [self.editBtn setImage:[UIImage imageNamed:@"editok_btn.png"] forState:UIControlStateHighlighted];
    [self.editBtn addTarget:self action:@selector(commitUpdate) forControlEvents:UIControlEventTouchUpInside];
   
}

- (void)commitUpdate
{
    _isEditing = NO;
    [self.personalInfoTableView reloadData];
    
    [self.editBtn setBackgroundImage:[UIImage imageNamed:@"edit_light.png"] forState:UIControlStateHighlighted];
    [self.editBtn setImage:[UIImage imageNamed:@"edit_btn.png"] forState:UIControlStateNormal];
    [self.editBtn setImage:[UIImage imageNamed:@"edit_btn.png"] forState:UIControlStateHighlighted];
    [self.editBtn addTarget:self action:@selector(tapOnUpdateBtn:) forControlEvents:UIControlEventTouchUpInside];
    
    if (!_hasChanged) {
        return;
    }
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    if (_tempUser.gender) {
        
        if ([@"Girl" isEqualToString:_tempUser.gender]) {
            
            [params setObject:@"F" forKey:@"gender"];
        }
        else if ([@"Boy" isEqualToString:_tempUser.gender]) {
            
            [params setObject:@"M" forKey:@"gender"];
        }
    }
    if (_tempUser.exam) {
        if ([@"SAT" isEqualToString:_tempUser.exam]) {
            
            [params setObject:@"0" forKey:@"exam"];
        }
        else if ([@"GRE" isEqualToString:_tempUser.exam]) {
            
            [params setObject:@"1" forKey:@"exam"];
        }
        else if ([@"GMAT" isEqualToString:_tempUser.exam]) {
            
            [params setObject:@"2" forKey:@"exam"];
        }
        else {
            
            [params setObject:@"-1" forKey:@"exam"];
        }
    }
    if (_tempUser.year) {
        [params setObject:_tempUser.year forKey:@"year"];
    }
    if (_tempUser.country) {
        [params setObject:_tempUser.country forKey:@"country"];
    }
    if (_tempUser.city) {
        [params setObject:_tempUser.city forKey:@"city"];
    }
    if (_tempUser.dreamSchool) {
        [params setObject:_tempUser.dreamSchool forKey:@"dreamSchool"];
    }
    if (_tempUser.status) {
        [params setObject:_tempUser.status forKey:@"status"];
    }
    
    [params setObject:[UserManager sharedManager].currentUser.userId forKey:@"id"];
    
    [[ServiceHelper sharedService] requestServerForMethod:HotWordRequestTypeUpdateInfo WithParameters:params AndCallBackScope:self AndSuccessSel:@"updateSuccess:" AndFailedSel:@"updateFailed:"];
    [[HTActivityIndicator currentIndicator] displayActivity:@"Updating..."];
}

- (IBAction)tapOnCancel:(id)sender {
    
    [UIView animateWithDuration:0.3 
                     animations:^{
                         self.pickContainerView.top = self.view.height;
                     }];
}

- (IBAction)tapOnConfirmBtn:(id)sender {
    _hasChanged = YES;
    _activeLabel.textColor = [UIColor whiteColor];
    switch (_updateType) {
        case HotWordUpdateDataGender:
            _activeLabel.text = [GENDER_ARRAY objectAtIndex:[self.dataSelectPicker selectedRowInComponent:0]];
            _tempUser.gender = _activeLabel.text;
            break;
            
        case HotWordUpdateDataExam:
            _activeLabel.text = [EXAM_ARRAY objectAtIndex:[self.dataSelectPicker selectedRowInComponent:0]];
            _tempUser.exam = _activeLabel.text;
            break;
        case HotWordUpdateDataAge:
            _activeLabel.text = [AGE_ARRAY objectAtIndex:[self.dataSelectPicker selectedRowInComponent:0]];
            _tempUser.year = _activeLabel.text;
            break;
        default:
            break;
    }
    [UIView animateWithDuration:0.3 
                     animations:^{
                         self.pickContainerView.top = self.view.height;
                     }];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 1) {
        [[UserManager sharedManager] removeLoginUser];
        [self.navigationController popToRootViewControllerAnimated:YES];
    }
}

- (void)updateSuccess:(NSObject *)result
{
    _hasChanged = NO;
    if (![result isKindOfClass:[NSDictionary class]]) {
        [[HTActivityIndicator currentIndicator] displayMessage:@"Update Failed!"];
        return;
    }
    NSDictionary *dic = (NSDictionary *)result;
    NSString *code = [dic objectForKey:@"code"];
    if ([@"0" isEqualToString:code]) {
        [[UserManager sharedManager] saveLoginUser:_tempUser];
        [[HTActivityIndicator currentIndicator] displayMessage:@"Update Succeed!"];
    }
    else {
        
        NSString *error = [UtilHelper getStringValue:[dic objectForKey:@"msg"]];
        [[HTActivityIndicator currentIndicator] displayMessage:error];
    }
}

- (void)updateFailed:(NSObject *)result
{
    _hasChanged = NO;
    [[HTActivityIndicator currentIndicator] displayMessage:@"Update Failed!"];
}

- (void)UserHeadInfoCellHeadDidSelected:(UserHeadInfoCell *)cell selectIndex:(NSInteger)index
{
    _headSelectIndex = index;
    _headInfoCell = [cell retain];
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil 
                                                             delegate:self 
                                                    cancelButtonTitle:@"Cancel" 
                                               destructiveButtonTitle:nil 
                                                    otherButtonTitles:@"Camera", @"Photo Library", nil];
    
    actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
    [actionSheet showInView:self.view.window];
    [actionSheet release];
}

#pragma mark ActionSheetDelegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0) 
    {
        BOOL isCameraAvaible = NO;
        isCameraAvaible = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
        if (!isCameraAvaible) 
        {
            [[HTActivityIndicator currentIndicator] displayMessage:@"No Camera!"];
            return;
        }
        UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
        imagePickerController.delegate = self;
        imagePickerController.allowsEditing = YES;
        imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
        [self presentModalViewController:imagePickerController animated:YES];
        [imagePickerController release];
        
    }
    else if (buttonIndex == 1)
    {
        UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];        
        imagePickerController.delegate = self;
        imagePickerController.allowsEditing = YES;
        imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        [self presentModalViewController:imagePickerController animated:YES];
        [imagePickerController release];
    }
}

#pragma mark - ImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{
    
    UIImage *image = (UIImage *)[info objectForKey:UIImagePickerControllerEditedImage];
    UIGraphicsBeginImageContext(CGSizeMake(240, 240));
    [image drawInRect:CGRectMake(0, 0, 240, 240)];
    UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();              
    
    [self dismissModalViewControllerAnimated:YES];
    switch (_headSelectIndex) {
        case 0:
            _headInfoCell.headImageView.image = scaledImage;
            break;
        case 1:
            _headInfoCell.headImageView1.image = scaledImage;
            break;
        case 2:
            _headInfoCell.headImageView2.image = scaledImage;
            break;
            
        default:
            break;
    }
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setObject:[UserManager sharedManager].currentUser.userId forKey:@"id"];
    [params setObject:scaledImage forKey:@"userfile"];
    [params setObject:[NSString stringWithFormat:@"%d", _headSelectIndex] forKey:@"type"];
    [[ServiceHelper sharedService] requestServerForMethod:HotWordRequestTypeUploadPic WithParameters:params AndCallBackScope:self AndSuccessSel:@"updatePicScuccess:" AndFailedSel:@"updatePicFailed:"];
    [[HTActivityIndicator currentIndicator] displayActivity:@"Uploading Image..."];
    
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker 
{
    [self dismissModalViewControllerAnimated:YES];
    
}

- (void)updatePicScuccess:(NSObject *)result
{
    NSString *avatorStr = [(NSDictionary *)result objectForKey:@"msg"];
    switch (_headSelectIndex) {
        case 0:
            if (![UserManager sharedManager].currentUser.avater || [@"" isEqualToString:[UserManager sharedManager].currentUser.avater]) {
                [UserManager sharedManager].currentUser.avater = avatorStr;
            }
            [[ITTImageCacheManager sharedManager] saveImage:_headInfoCell.headImageView.image withUrl:[IMAGE_BASE_URL stringByAppendingString:[UserManager sharedManager].currentUser.avater]];
            break;
        case 1:
            if (![UserManager sharedManager].currentUser.avater1 || [@"" isEqualToString:[UserManager sharedManager].currentUser.avater1]) {
                [UserManager sharedManager].currentUser.avater1 = avatorStr;
            }
            [[ITTImageCacheManager sharedManager] saveImage:_headInfoCell.headImageView1.image withUrl:[IMAGE_BASE_URL stringByAppendingString:[UserManager sharedManager].currentUser.avater1]];
            break;
        case 2:
            if (![UserManager sharedManager].currentUser.avater2 || [@"" isEqualToString:[UserManager sharedManager].currentUser.avater2]) {
                [UserManager sharedManager].currentUser.avater2 = avatorStr;
            }
            [[ITTImageCacheManager sharedManager] saveImage:_headInfoCell.headImageView2.image withUrl:[IMAGE_BASE_URL stringByAppendingString:[UserManager sharedManager].currentUser.avater2]];
            break;
            
        default:
            break;
    }
    [[HTActivityIndicator currentIndicator] displayCompleted:@"Upload Succeed!"];
}

- (void)updatePicFailed:(NSObject *)result
{
    
    [[HTActivityIndicator currentIndicator] displayFailed:@"Upload Failed!"];
}

- (void)UserInfoCellBeginEdit:(UserInfoCell *)cell
{
    [UIView animateWithDuration:0.3 
                     animations:^{
                         self.pickContainerView.top = self.view.height;
                     }];
    if (_activeField) {
        [_activeField release];
        _activeField = nil;
    }
    _activeField = [cell.userInfoTextField retain];
    _activeField.textColor = [UIColor whiteColor];
    
    NSIndexPath *indexPath = [self.personalInfoTableView indexPathForCell:cell];
    CGRect selectedRect = [self.personalInfoTableView rectForRowAtIndexPath:indexPath];
    if (selectedRect.origin.y > 150) {
        if (cell.indexPath.row == 7) {
            
            [self.personalInfoTableView setContentOffset:CGPointMake(0, selectedRect.origin.y - 140) animated:YES];
        }
        else {
            
            [self.personalInfoTableView setContentOffset:CGPointMake(0, selectedRect.origin.y - 150) animated:YES];
        }
    }
}

- (void)UserInfoCellEndEdit:(UserInfoCell *)cell
{
    _hasChanged = YES;
    NSIndexPath *indexPath = cell.indexPath;
    NSString *labelStr = cell.userInfoLabel.text;
    NSString *fieldStr = cell.userInfoTextField.text;
    switch (indexPath.row) {
        case 1:
            _tempUser.gender = labelStr;
            break;
        case 2:
            _tempUser.exam = labelStr;
            break;
        case 3:
            _tempUser.year = fieldStr;
            break;
        case 4:
            _tempUser.country = fieldStr;
            break;
        case 5:
            _tempUser.city = fieldStr;
            break;
        case 6:
            _tempUser.dreamSchool = fieldStr;
            break;
        case 7:
            _tempUser.status = cell.statusTextView.text;
            [cell.statusTextView resignFirstResponder];
            break;
            
        default:
            break;
    }
}

- (void)UserInfoCellShowPicker:(UserInfoCell *)cell
{
    [_activeField resignFirstResponder];
    if (_activeLabel) {
        [_activeLabel release];
        _activeLabel = nil;
    }
    _activeLabel = [cell.userInfoLabel retain];
    switch (cell.indexPath.row) {
        case 1:
            _updateType = HotWordUpdateDataGender;
            break;
        case 2:
            _updateType = HotWordUpdateDataExam;
            break;
            
        case 3:
            _updateType = HotWordUpdateDataAge;
            break;
            
            
        default:
            break;
    }
    [self.dataSelectPicker reloadAllComponents];
    [UIView animateWithDuration:0.3 
                     animations:^{
                         self.pickContainerView.bottom = self.view.height;
                     }];

}

- (void)UserInfoCellChooseDreamSchool:(UserInfoCell *)cell
{
    
    if (_activeLabel) {
        [_activeLabel release];
        _activeLabel = nil;
    }
    _activeLabel = [cell.userInfoLabel retain];
    DreamSchoolViewController *dreamSchoolViewController = [[[DreamSchoolViewController alloc] init] autorelease];
    dreamSchoolViewController.delegate = self;
    [self.navigationController pushViewController:dreamSchoolViewController animated:YES];
}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{    
    if (self.pickContainerView.top >= self.view.height) {
        
        [self hideKeybord];
    }
    [UIView animateWithDuration:0.3 
                     animations:^{
                         self.pickContainerView.top = self.view.height;
                     }];
}

- (void)hideKeybord
{
    for (UserInfoCell *cell in self.personalInfoTableView.visibleCells) {
        if ([cell respondsToSelector:@selector(userInfoTextField)]) {
            
            [cell.userInfoTextField resignFirstResponder];
        }
        if([cell respondsToSelector:@selector(statusTextView)]){
            [cell.statusTextView resignFirstResponder];
        }
    }
}

- (void)hanldTapGesture:(UIGestureRecognizer *)recognizer
{
    if (self.pickContainerView.top >= self.view.height) {
        
        [self hideKeybord];
    }
    [UIView animateWithDuration:0.3 
                     animations:^{
                         self.pickContainerView.top = self.view.height;
                     }];
}


-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    if ([touch.view isKindOfClass:[UIButton class]] || [touch.view isDescendantOfView:self.pickContainerView]) {
        return NO; 
    }
    return YES;
}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}

// returns the # of rows in each component..
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    switch (_updateType) {
        case HotWordUpdateDataGender:
            return [GENDER_ARRAY count];
            break;
            
        case HotWordUpdateDataExam:
            return [EXAM_ARRAY count];
            break;
            
        case HotWordUpdateDataAge:
            return [AGE_ARRAY count];
            break;
        default:
            break;
    }
    
    return 0;
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    switch (_updateType) {
        case HotWordUpdateDataGender:
            return [GENDER_ARRAY objectAtIndex:row];
            break;
            
        case HotWordUpdateDataExam:
            return [EXAM_ARRAY objectAtIndex:row];
            break;
        case HotWordUpdateDataAge:
            return [AGE_ARRAY objectAtIndex:row];
            break;
        default:
            break;
    }
    return nil;
}

- (void)DreamSchoolViewControllerDidSelected:(School *)school
{
    _hasChanged = YES;
    _tempUser.dreamSchool = school.schoolId;
    _tempUser.dreamSchoolCN = school.schoolCn;
    _tempUser.dreamSchoolEN = school.schoolEn;
    _activeLabel.text = _tempUser.dreamSchoolCN;
    _activeLabel.textColor = [UIColor whiteColor];
}

- (void)dealloc
{
    [_tempUser release];
    [_activeLabel release];
    [_activeField release];
    [_headInfoCell release];
    [personalInfoTableView release];
    [backBtn release];
    [inboxBtn release];
    [friendBtn release];
    [meHeaderView release];
    [logoutFooterView release];
    [dataSelectPicker release];
    [pickContainerView release];
    [editBtn release];
    [super dealloc];
}

@end
